/*********************************************************************
  BUTTONTEMPLATE
----------------------------------------------------------------------
  b1 = new JButton(_name of button_);
  b1.setActionCommand(_action string_);
  b1.addActionListener(this);
  _pagename_.add(b1);

  PAGE CHANGE TEMPLATE
---------------------------------------------------------------------
  if (_action string_.equals(e.getActionCommand())) {
    System.err.println(_print out name of pagename in terminal_);
    ((CardLayout)this.pages.getLayout()).show(pages, _keywork for page_);      
  }
 ******************************************************************** */
package gas.view;

import java.util.*;

import gas.model.*;
import gas.controller.*;
import gas.controller.ModelController.GasStationAdapter;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BasicGui extends JFrame implements ActionListener {
    private static boolean DEBUG = false;

    // strings used to specify page when using CardLayout
    final static String DEFAULT = "default page";
    final static String LOGIN = "login page";
    final static String CREATEACCOUNT = "create account page";
    final static String HOME = "home page";
    final static String ACCOUNTSETTINGS = "account settings page";
    final static String SEARCH = "search page";
    final static String NEWSTATION = "new station page";
    final static String STATION = "station page";

    private JPanel pages; // name for CardLayout
    private JPanel defaultPage;
    private JPanel loginPage;
    private JPanel createAccountPage;
    private JPanel homePage;
    private JPanel accountSettingsPage;
    private JPanel searchPage;
    private JPanel newStationPage;
    private JPanel stationPage;

    private JTextField username;
    private JTextField usernameCreate;
    private JPasswordField password;
    private JPasswordField passwordCreate;
    private JTextField emailCreate;
    private JTextField address;

    //ADMIN Specific
    private JLabel priceUpdateLabel;
    private JTextField priceUpdate;
    private JButton priceUpdateButton;
  
    private JTextField proximityValue;
    private JTextField costValue;
    private JTextField roundTripCost;
    private JTextField waitTolerance;

    int num_radio_buttons = 10;
    private ButtonGroup milageGroup;
    private JRadioButton[] milageButtons;
    
    private JTextArea stationStats;

    private JTextArea userStats;
    private int stationNumber = 0;

    private GridBagConstraints c;

    /******************* ALFRED'S REVISION *************************/
    private ArrayList<ModelController.GasStationAdapter> gsaAL;
    private JComboBox jcb;

    /****************
     * 0 = create account page 1 = login page 2 = account page 3 = search page
     ****************/
    int num_errorBox = 4;
    private JLabel[] errorBox = new JLabel[num_errorBox];

    int NUM_RESULTS = 10;

    private JLabel[] resultsName = new JLabel[NUM_RESULTS];
    private JLabel[] resultsLocation = new JLabel[NUM_RESULTS];
    private JLabel[] resultsPrice = new JLabel[NUM_RESULTS];
    private JLabel[] resultsFreshness = new JLabel[NUM_RESULTS];
    private JButton[] resultsChangePrice = new JButton[NUM_RESULTS];

    public BasicGui() {

        if (DEBUG)
            System.out.println("Construction BasicGUI");

        this.setSize(640, 960); // resolution of an ipod touch

        c = new GridBagConstraints();

        /***** INITIALIZE TEXT FIELDS *****/
        username = new JTextField();
        password = new JPasswordField();
        usernameCreate = new JTextField();
        passwordCreate = new JPasswordField();
        emailCreate = new JTextField();
        address = new JTextField();
        //Admin Specific
        priceUpdateLabel = new JLabel();
        priceUpdate = new JTextField();
        priceUpdateButton = new JButton();

        // Preferences
        proximityValue = new JTextField();
        costValue = new JTextField();
        roundTripCost = new JTextField();
        waitTolerance = new JTextField();

        // results
        for (int i = 0; i < NUM_RESULTS; i++) {
            resultsName[i] = new JLabel(" . . ");
            resultsLocation[i] = new JLabel(" . . ");
            resultsPrice[i] = new JLabel(" . . ");
            resultsFreshness[i] = new JLabel(" . . ");
            resultsChangePrice[i] = new JButton();
        }
        for (int i = 0; i < num_errorBox; i++) {
            errorBox[i] = new JLabel(" ");
            errorBox[i].setForeground(Color.RED);
        }

        // radioButtons
        milageGroup = new ButtonGroup();
        milageButtons = new JRadioButton[num_radio_buttons];

        /***** INITIALIZE TEXT AREAS *****/
        userStats = new JTextArea();
        stationStats = new JTextArea();

        /***** DEFAULT PAGE LAYOUT *****/
        defaultPage = new JPanel();
        this.makeDefaultPage(defaultPage);

        /***** LOGIN PAGE LAYOUT *****/
        loginPage = new JPanel();
        this.makeLoginPage(loginPage);

        /***** CREATE ACCOUNT PAGE LAYOUT *****/
        createAccountPage = new JPanel();
        this.makeCreateAccountPage(createAccountPage);

        /***** HOME PAGE LAYOUT *****/
        homePage = new JPanel();
        this.makeHomePage(homePage);

        /***** ACCOUNT SETTINGS PAGE LAYOUT *****/
        accountSettingsPage = new JPanel();
        this.makeAccountSettingsPage(accountSettingsPage);

        /***** SEARCH PAGE LAYOUT *****/
        searchPage = new JPanel();
        this.makeSearchPage(searchPage);

        /***** NEWSTATION PAGE LAYOUT *****/
        newStationPage = new JPanel();
        this.makeNewStationPage(newStationPage);

        /***** STATION PAGE LAYOUT *****/
        stationPage = new JPanel();
        this.makeStationPage(stationPage);

        // create page manager/storage
        pages = new JPanel(new CardLayout());
        pages.add(defaultPage, DEFAULT);
        pages.add(loginPage, LOGIN);
        pages.add(createAccountPage, CREATEACCOUNT);
        pages.add(homePage, HOME);
        /***** SEARCH PAGE LAYOUT *****/
        searchPage = new JPanel();
        this.makeSearchPage(searchPage);

        /***** NEWSTATION PAGE LAYOUT *****/
        newStationPage = new JPanel();
        this.makeNewStationPage(newStationPage);

        /***** STATION PAGE LAYOUT *****/
        stationPage = new JPanel();
        this.makeStationPage(stationPage);

        // create page manager/storage
        pages = new JPanel(new CardLayout());
        pages.add(defaultPage, DEFAULT);
        pages.add(loginPage, LOGIN);
        pages.add(createAccountPage, CREATEACCOUNT);
        pages.add(homePage, HOME);
        pages.add(accountSettingsPage, ACCOUNTSETTINGS);
        pages.add(searchPage, SEARCH);
        pages.add(newStationPage, NEWSTATION);
        pages.add(stationPage, STATION);
        this.add(pages);

        // Specifies what clicking the exit button will do
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                // closing the window (aka clicking the X in the corner)
                // means exiting the program
                System.err.println("Exiting via windowClosing");

                /***
                 * TODO: Call logout scenario requires closing of database.
                 */
                try {
                    DatabaseController.cleanDB();
                    DatabaseController.storeDB(null);
                    DatabaseController.closeDB();
                } catch (Exception e) {
                    System.err.println("Well... Shit...");
                    e.printStackTrace();
                }

                System.exit(0);
            }
        });

        this.setVisible(true);

        if (DEBUG)
            System.out.println("BasicGUI construction complete");
    }

    // SelfTest
    public static void main(String[] args) {
        // construct the frame
        JFrame mainGui = new BasicGui();
    }

    // GOTO PAGE FUNCTIONS
    public void goto_defaultPage() {
        ((CardLayout) this.pages.getLayout()).show(pages, DEFAULT);
    }

    // construct and update the login page
    public void goto_loginPage() {
        ((CardLayout) this.pages.getLayout()).show(pages, LOGIN);
        username.setText("");
        password.setText("");
    }

    public void goto_createAccountPage() {
        ((CardLayout) this.pages.getLayout()).show(pages, CREATEACCOUNT);
        usernameCreate.setText("");
        passwordCreate.setText("");
        emailCreate.setText("");
    }

    public void goto_homePage() {
        ((CardLayout) this.pages.getLayout()).show(pages, HOME);
        userStats.setText(ModelController.currentUser.toString());

        /*
         * homePage.add(new JLabel("homepage")); if( ModelController.currentUser
         * != null ){ homePage.add(new JLabel("Hello, " +
         * ModelController.currentUser.toString())); } else{
         * System.err.println("No Current User."); homePage.add(new
         * JLabel("HOME")); }
         */
    }

    public void goto_accountSettingsPage() {
        ((CardLayout) this.pages.getLayout()).show(pages, ACCOUNTSETTINGS);

        // USE THIS TO GET THE CURRENT SELECTED BUTTON'S NAME
        // milageGroup.getSelection().getActionCommand();

        // USE THIS TO SET THE CURRENT BUTTON. WARNING:CHECK FOR OFF-BY-ONE
        // ERRORS(;
        // milageGroup.setSelected(milageButtons[index_of_button])

        if (ModelController.isLoggedIn()) {
            Preferences p = ModelController.currentUser.getPrefs();
            if (p != null) {
                int a = p.getProximityValue();
                int b = p.getCostValue();
                int c = p.getroundTripCost();
                int d = p.getWaitTolerance();

                // RADIOButton thing.
//                proximityValue.setText(String.format("%d", a));
                milageGroup.setSelected(milageButtons[a-1].getModel(), true);
                
                jcb.setSelectedItem(LocationsEnum.getMatch(
                        ModelController.currentUser.getPrefs().getLocation())
                        .location());              
                //roundTripCost.setText(String.format("%d", c));                
                costValue.setText(String.format("%d", b));
                System.err.println(" Setting to: "
                        + LocationsEnum.getMatch(
                                ModelController.currentUser.getPrefs()
                                        .getLocation()).location());
                waitTolerance.setText(String.format("%d", d));
            } else {
                System.err.println(" ERROR ");
            }
        }
    }

    public void goto_searchPage() {
        ((CardLayout) this.pages.getLayout()).show(pages, SEARCH);
    }

    public void updateSearchPage() {
        JPanel results = new JPanel();
        results.setLayout(new GridBagLayout());

        /******************* ALFRED'S REVISION *************************/
        gsaAL = new ArrayList<ModelController.GasStationAdapter>();
        for (int i = 0; i < NUM_RESULTS
                && i < ModelController.getStationBase().getGasTable().size(); i++) {// currentGasList.size();
                                                                                    // i++){
            gsaAL.add(ModelController.currentGasList.poll()); // getGasStation(i));
                                                              // //currentGasList.poll();//
            resultsName[i].setText(gsaAL.get(i).gs.getStationName());
            resultsLocation[i].setText(gsaAL.get(i).gs.getLocation());
            resultsPrice[i].setText(gsaAL.get(i).gs.inDollars(gsaAL.get(i).gs
                    .getCurrentPrice()));
            resultsFreshness[i].setText(new Float(gsaAL.get(i)
                    .getCompatability() * 100).intValue() + "%");
        }
        /*
         * for (int i = 0; i < gsaAL.size(); i++)
         * System.err.println(gsaAL.get(i).getCV());
         */}

    public void goto_newStationPage() {
        ((CardLayout) this.pages.getLayout()).show(pages, NEWSTATION);
    }

    public void goto_stationPage(ModelController.GasStationAdapter station) {
        ((CardLayout) this.pages.getLayout()).show(pages, STATION);
//        gsaAL.get(stationNumber).gs.getStationName();
 //       gsaAL.get(stationNumber).gs.getLocation();
  //      gsaAL.get(stationNumber).gs.inDollars(gsaAL.get(stationNumber).gs.getCurrentPrice());
        stationStats.setText(gsaAL.get(stationNumber).gs.toString());
 
        priceUpdate.setText(gsaAL.get(stationNumber).gs.inDollars(gsaAL.get(stationNumber).gs.getCurrentPrice()));
            
        
    }

    public void actionPerformed(ActionEvent e) {
        String action = e.getActionCommand();
        System.out.println(e.paramString());

        if ("search".equals(action)) {
            // SEARCH
            if (DEBUG)
                System.out.println("Searching for results");

            if (ModelController.getMatchingStations()) {
                this.updateSearchPage();
            } else {
                errorBox[3].setText("FAIL");
            }
        }

        /******************* ALFRED'S REVISION *************************/
        if ("station1".equals(action)) {
            ModelController.GasStationAdapter a = gsaAL.get(0); // ModelController.getGasStation(0);
            this.goto_stationPage(a);
        }
        if ("station2".equals(action)) {
            ModelController.GasStationAdapter a = gsaAL.get(1); // ModelController.getGasStation(1);
            this.goto_stationPage(a);
        }
        if ("station3".equals(action)) {
            ModelController.GasStationAdapter a = gsaAL.get(2); // ModelController.getGasStation(2);
            this.goto_stationPage(a);
        }
        if ("station4".equals(action)) {
            ModelController.GasStationAdapter a = gsaAL.get(3); // ModelController.getGasStation(3);
            this.goto_stationPage(a);
        }
        if ("station5".equals(action)) {
            ModelController.GasStationAdapter a = gsaAL.get(4); // ModelController.getGasStation(4);
            this.goto_stationPage(a);
        }

        /****For Admin Buttons****/
        if ("priceButton0".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(0);
            stationNumber = 0;
            this.goto_stationPage(a);
        }
        if ("priceButton1".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(1);
            stationNumber = 1;
            this.goto_stationPage(a);
        }
        if ("priceButton2".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(2);
            stationNumber = 2;
            this.goto_stationPage(a);
        }
        if ("priceButton3".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(3);
            stationNumber = 3;
            this.goto_stationPage(a);
        }
        if ("priceButton4".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(4);
            stationNumber = 4;
            this.goto_stationPage(a);
        }
        if ("priceButton5".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(5);
            stationNumber = 5;
            this.goto_stationPage(a);
        }
        if ("priceButton6".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(6);
            stationNumber = 6;
            this.goto_stationPage(a);
        }
        if ("priceButton7".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(7); 
            stationNumber = 7;
            this.goto_stationPage(a);
        }
        if ("priceButton8".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(8); 
            stationNumber = 8;
            this.goto_stationPage(a);
        }
        if ("priceButton9".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(9);
            stationNumber = 9;
            this.goto_stationPage(a);
        }

        if("updatePrice".equals(action) && gsaAL != null){
            ModelController.GasStationAdapter a = gsaAL.get(stationNumber); 
            String s = priceUpdate.getText();
            float f = Float.valueOf(s.trim()).floatValue();
            f *= 100;
            gsaAL.get(stationNumber).gs.setCurrentPrice((int)f);
        }


        if ("gotoCreateAccount".equals(action)) {
            // go to createAccountPage
            if (DEBUG)
                System.out.println("Going to Create Account Page");
            this.goto_createAccountPage();

        }
        if ("gotoLogin".equals(action)) {
            // go to LoginPage
            if (DEBUG)
                System.out.println("Going to Login Page");
            this.goto_loginPage();
            ((CardLayout) this.pages.getLayout()).show(pages, LOGIN);

        }
        if ("login".equals(action)) {
            errorBox[1].setText(" ");
            // login and go into homepage
            if (DEBUG)
                System.out.println("  Logging in as:" + "\n username: "
                        + username.getText() + "\n password: "
                        + new String(password.getPassword()));
            for (char it : password.getPassword())
                System.err.print(it);
            System.err.println("[END]");
            System.err.println(new String(password.getPassword()));
            if (ModelController.login(username.getText(),
                    new String(password.getPassword()))){

                //ADMIN BUTTONS CHECK
                if(ModelController.currentUser.isAdmin()){
                    for(int i = 0; i < resultsChangePrice.length; i++)
                        resultsChangePrice[i].setVisible(true);
                    priceUpdateLabel.setVisible(true);
                    priceUpdate.setVisible(true);
                    priceUpdateButton.setVisible(true);
                }else{
                    for(int i = 0; i < resultsChangePrice.length; i++)
                        resultsChangePrice[i].setVisible(false);
                    priceUpdateLabel.setVisible(false);
                    priceUpdate.setVisible(false);
                    priceUpdateButton.setVisible(false);
                }

                this.goto_homePage();
            }
            else {
                // Display Error Dialog
                errorBox[1].setText("Please Re-enter Password");
                password.setText("");
            }
        }
        if ("createAccount".equals(action)) {
            errorBox[0].setText(" ");
            // create account and go into homepage
            if (DEBUG)
                System.out.println("  Creating New Account" + "\n  username: "
                        + usernameCreate.getText() + "\n  password: "
                        + new String(passwordCreate.getPassword())
                        + "\n  email: " + emailCreate.getText());
            if (ModelController.createUser(usernameCreate.getText(),
                    new String(passwordCreate.getPassword()),
                    emailCreate.getText(), true)) {
                this.goto_homePage();
            } else {
                // Display Error Dialog
                errorBox[0].setText("Invalid Entries");
            }
        }
        if ("home".equals(action)) {
            if (DEBUG)
                System.out.println("Going to Home Page.");
            this.goto_homePage();
        }
        if ("gotoAccount".equals(action)) {
            // go to account settings page
            if (DEBUG)
                System.out.println("Going to AccountPage");
            this.goto_accountSettingsPage();
        }

        if ("gotoSearch".equals(action)) {
            // go to Search Page
            if (DEBUG)
                System.out.println("Going to SearchPage");
            this.goto_searchPage();
        }

        if ("logout".equals(action)) {
            // logout and go to the default page
            if (DEBUG)
                System.out.println("LOGGING OUT");
            ModelController.logout();
            this.goto_defaultPage();
        }
        if ("goBackToDefault".equals(action)) {
            // go back to default page
            if (DEBUG)
                System.out.println("goingBacktoDefault");
            ModelController.logout();
            this.goto_defaultPage();
        }
        if ("setPreferences".equals(action)) {
            // save preferences
            if (DEBUG)
                System.out.println("Saving Preferences");

//            int a = Integer.valueOf(proximityValue.getText()).intValue();
//          JRadioButton jrb = (JRadioButton)(milageGroup.getSelection().getSelectedObjects())[0];
            int testJRBNum = Integer.valueOf(milageGroup.getSelection().getActionCommand().split("milage")[1]).intValue();
            System.out.println(milageGroup.getSelection().getActionCommand()); // jrb.getAccessibleContext().getAccessibleText().getSelectedText());
            System.out.println(testJRBNum); // jrb.getAccessibleContext().getAccessibleText().getSelectedText());
            int a = testJRBNum;
                
            int b = Integer.valueOf(costValue.getText()).intValue();
            int c = 0;// Integer.valueOf(roundTripCost.getText()).intValue();
            String cl = (String) jcb.getSelectedItem();
            int d = Integer.valueOf(waitTolerance.getText()).intValue();

            ModelController.currentUser.getPrefs().setAll(a, b, cl, d);

            this.goto_accountSettingsPage();
        }

    }

    // Use this function when creating the page layouts
    // and makes the Banner that goes at the top
    protected void setBanner(JPanel panel) {
        panel.setLayout(new GridBagLayout());
        JPanel banner = new JPanel();

        banner.setLayout(new GridBagLayout());

        JButton logout = new JButton("Logout");
        logout.setActionCommand("logout");
        logout.addActionListener(this);
        setConstraints(0, 1, 1, 1, 0.5f, 0.0f, false);
        c.ipady = 20;
        banner.add(logout, c); // add logout button

        JButton home = new JButton("Home");
        home.setActionCommand("home");
        home.addActionListener(this);
        setConstraints(1, 1, 1, 1, 0.5f, 0.0f, false);
        c.ipady = 20;
        banner.add(home, c);

        JButton account = new JButton("Account");
        account.setActionCommand("gotoAccount");
        account.addActionListener(this);
        setConstraints(2, 1, 1, 1, 0.5f, 0.0f, false);
        c.ipady = 20;
        banner.add(account, c); // add goto account button

        JButton search = new JButton("SEARCH!");
        search.setActionCommand("gotoSearch");
        search.addActionListener(this);
        setConstraints(3, 1, 1, 1, 0.5f, 0.0f, false);
        c.ipady = 20;
        banner.add(search, c); // add Search button

        setConstraints(0, 0, 4, 1, 1.0f, 0.0f, false);
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.PAGE_END;
        panel.add(banner, c);
    }

    // **********************PAGE LAYOUTS*************************************//

    protected void makeDefaultPage(JPanel panel) {
        panel.setLayout(new GridBagLayout());

        setConstraints(0, 0, 1, 1, 0.0f, 0.0f, false);
        panel.add(new JLabel("WELCOME TO YOUR BEST GAS!"), c);

        JButton b1 = new JButton("Create New Account");
        b1.setActionCommand("gotoCreateAccount");
        b1.addActionListener(this);
        setConstraints(0, 1, 1, 1, 0.5f, 0.0f, true);
        c.ipady = 50;
        panel.add(b1, c); // add create account button

        JButton b2 = new JButton("Login as Existing User");
        b2.setActionCommand("gotoLogin");
        b2.addActionListener(this);
        setConstraints(1, 1, 1, 1, 0.5f, 0.0f, true);
        c.ipady = 50;
        panel.add(b2, c); // add login button
    }

    protected void makeLoginPage(JPanel panel) {
        panel.setLayout(new GridBagLayout());

        setConstraints(1, 0, 2, 1, 0.0f, 0.0f, false);
        panel.add(errorBox[1], c);

        setConstraints(0, 11, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("Username:"), c);
        setConstraints(1, 11, 2, 1, 0.7f, 0.0f, false);
        panel.add(username, c); // username input

        setConstraints(0, 12, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("Password:"), c);
        setConstraints(1, 12, 2, 1, 0.7f, 0.0f, false);
        panel.add(password, c); // password input

        JButton b2 = new JButton("Go Back");
        b2.setActionCommand("goBackToDefault");
        b2.addActionListener(this);
        setConstraints(1, 13, 1, 1, 0.5f, 0.0f, true);
        panel.add(b2, c); // go Back button

        JButton b3 = new JButton("Login");
        b3.setActionCommand("login");
        b3.addActionListener(this);
        setConstraints(2, 13, 1, 1, 0.5f, 0.0f, true);
        panel.add(b3, c); // enter button
    }

    protected void makeCreateAccountPage(JPanel panel) {
        panel.setLayout(new GridBagLayout());

        setConstraints(1, 5, 2, 1, 0.0f, 0.0f, false);
        panel.add(errorBox[0], c);

        setConstraints(0, 10, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("Username:"), c);
        setConstraints(1, 10, 2, 1, 0.7f, 0.0f, false);
        panel.add(usernameCreate, c); // username input

        setConstraints(0, 11, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("Password:"), c);
        setConstraints(1, 11, 2, 1, 0.7f, 0.0f, false);
        panel.add(passwordCreate, c); // password input

        setConstraints(0, 12, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("Email Address:"), c);
        setConstraints(1, 12, 2, 1, 0.7f, 0.0f, false);
        panel.add(emailCreate, c); // email input

        JButton b2 = new JButton("Go Back");
        b2.setActionCommand("goBackToDefault");
        b2.addActionListener(this);
        setConstraints(1, 13, 1, 1, 0.5f, 0.0f, true);
        panel.add(b2, c); // go Back button

        JButton b4 = new JButton("Create Account");
        b4.setActionCommand("createAccount");
        b4.addActionListener(this);
        setConstraints(2, 13, 1, 1, 0.5f, 0.0f, true);
        panel.add(b4, c); // enter button

    }

    protected void makeHomePage(JPanel panel) {
        panel.setLayout(new GridBagLayout());
        this.setBanner(panel);

        setConstraints(1, 2, 1, 1, 0.0f, 0.0f, false);
        c.weightx = GridBagConstraints.RELATIVE;
        panel.add(new JLabel("home page"), c);

        setConstraints(0, 3, 1, 1, 0.0f, 0.0f, false);
        panel.add(userStats, c);

    }

    protected void makeAccountSettingsPage(JPanel panel) {
        panel.setLayout(new GridBagLayout());
        this.setBanner(panel);

        setConstraints(0, 3, 1, 1, 0.0f, 0.0f, false);
        panel.add(userStats, c); // Account information

        JButton b1 = new JButton("Change Password (**need to implement**) ");
        b1.setActionCommand("changePassword");
        b1.addActionListener(this);
        setConstraints(2, 4, 1, 1, 0.5f, 0.0f, true);
        panel.add(b1, c);

        setConstraints(1, 20, 3, 1, 1.0f, 0.0f, false);
        panel.add(new JLabel("My Preferences"), c);

        setConstraints(1, 21, 4, 1, 0.0f, 0.0f, false);
        panel.add(errorBox[2], c);

        setConstraints(0, 21, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("importance of distance:"), c);

        JPanel radioRow = new JPanel();
        for (int i = 0; i < milageButtons.length; i++) {
            milageButtons[i] = new JRadioButton("" + (i + 1));
            milageButtons[i].setActionCommand("milage" + (i + 1));
            milageButtons[i].addActionListener(this);
            milageGroup.add(milageButtons[i]);
            System.out.println("[BasicGui] Radio ButtonCount:"
                    + milageGroup.getButtonCount());
            setConstraints(i, 0, 1, 1, 1.0f, 1.0f, false);
            radioRow.add(milageButtons[i], c);
        }

        milageGroup.setSelected(milageButtons[0].getModel(), true);
        setConstraints(1, 21, 2, 1, 0.3f, 0.0f, false);
        panel.add(radioRow, c);
/*
         setConstraints(0, 24, 1, 1, 0.3f, 0.0f, false);
         panel.add(new JLabel("How far will you drive:"), c);
         setConstraints(1, 24, 2, 1, 0.7f, 0.0f, false);
         panel.add(proximityValue, c); // proximityValue input
*/
        
        setConstraints(0, 25, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("Where are you located? :"), c); //
        jcb = new JComboBox();
        for (LocationsEnum le : LocationsEnum.values())
            jcb.addItem(le.location());
        
        setConstraints(1, 25, 2, 1, 0.7f, 0.0f, false);
        panel.add(jcb, c);
        
        setConstraints(0, 26, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("How much will you pay:"), c);
        setConstraints(1, 26, 2, 1, 0.7f, 0.0f, false);
        panel.add(costValue, c); // costValue input

        

        /*
         * panel.add(new JLabel("How efficient will you be:"), c);
         * setConstraints(1, 26, 2, 1, 0.7f, 0.0f, false);
         * panel.add(roundTripCost, c); // roundTripCost input
         */

        setConstraints(0, 27, 1, 1, 0.3f, 0.0f, false);
        panel.add(new JLabel("How long will you wait:"), c);
        setConstraints(1, 27, 2, 1, 0.7f, 0.0f, false);
        panel.add(waitTolerance, c); // waitTolerance input

        JButton b2 = new JButton("Save Preferences");
        b2.setActionCommand("setPreferences");
        b2.addActionListener(this);
        setConstraints(2, 30, 1, 1, 0.5f, 0.0f, true);
        panel.add(b2, c); // add create account button

    }

    protected void makeSearchPage(JPanel panel) {
        panel.setLayout(new GridBagLayout());
        this.setBanner(panel);

        JButton b2 = new JButton("Find Me Gas!");
        b2.setActionCommand("search");
        b2.addActionListener(this);
        c.ipady = 15;
        c.insets = new Insets(10, 10, 10, 10);
        setConstraints(1, 2, 2, 1, 1.0f, 0.0f, true);
        panel.add(b2, c); // add create account button

        setConstraints(0, 3, 5, 1, 1.0f, 0.0f, false);
        c.weightx = GridBagConstraints.RELATIVE;
        panel.add(new JLabel("Top Ten Results"), c);

        setConstraints(0, 4, 5, 1, 1.0f, 0.0f, false);
        panel.add(errorBox[3], c);

        // *********label row
        setConstraints(0, 5, 1, 1, 1.0f, 0.0f, true);
        panel.add(new JLabel("GasStation"), c);
        setConstraints(1, 5, 1, 1, 1.0f, 0.0f, true);
        panel.add(new JLabel("City"), c);
        setConstraints(2, 5, 1, 1, 1.0f, 0.0f, true);
        panel.add(new JLabel("Price"), c);
        setConstraints(3, 5, 1, 1, 1.0f, 0.0f, true);
        panel.add(new JLabel("Compatibility"), c); // "Freshness"),c);

        for (int i = 0; i < NUM_RESULTS; i++) {
            setConstraints(0, 10 + i, 1, 1, 1.0f, 0.0f, true);
            panel.add(resultsName[i], c);
            setConstraints(1, 10 + i, 1, 1, 1.0f, 0.0f, true);
            panel.add(resultsLocation[i], c);
            setConstraints(2, 10 + i, 1, 1, 1.0f, 0.0f, true);
            panel.add(resultsPrice[i], c);
            setConstraints(3, 10 + i, 1, 1, 1.0f, 0.0f, true);
            panel.add(resultsFreshness[i], c);
            //ADMIN BUTTON
            resultsChangePrice[i] = new JButton("ChangePrice");
            resultsChangePrice[i].setActionCommand("priceButton"+i);
            resultsChangePrice[i].addActionListener(this);
            setConstraints(4, 10 + i, 1, 1, 1.0f, 0.0f, true);
            panel.add(resultsChangePrice[i],c);
            resultsChangePrice[i].setVisible(true);
        }
    }

    protected void makeNewStationPage(JPanel panel) {
        panel.setLayout(new GridBagLayout());
        this.setBanner(panel);
        setConstraints(1, 2, 1, 1, 0.0f, 0.0f, false);
        c.weightx = GridBagConstraints.RELATIVE;
        panel.add(new JLabel("NEW STATION"), c);

    }

    protected void makeStationPage(JPanel panel) {
        panel.setLayout(new GridBagLayout());
        this.setBanner(panel);
        setConstraints(1, 2, 1, 1, 0.0f, 0.0f, false);
        c.weightx = GridBagConstraints.RELATIVE;
        panel.add(new JLabel("STATION PAGE"), c);
       
        setConstraints(0,5,3,1,1.0f,0.0f, false);
        panel.add(stationStats, c);

        setConstraints(0, 10, 1, 1, 0.3f, 0.0f, false);
        priceUpdateLabel = new JLabel("Set Price");
        panel.add(priceUpdateLabel, c);
        setConstraints(1, 10, 2, 1, 0.7f, 0.0f, false);
        panel.add(priceUpdate, c); // username input

        priceUpdateButton = new JButton("Update Price");
        priceUpdateButton.setActionCommand("updatePrice");
        priceUpdateButton.addActionListener(this);
        setConstraints(1, 11, 2, 1, 0.7f, 0.0f, true);
        panel.add(priceUpdateButton, c); // username input
        


    }

    protected void setConstraints(int mgridx, int mgridy, int mgridwidth,
            int mgridheight, float mweightx, float mweighty, boolean button) {
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = mgridx;
        c.gridy = mgridy;
        c.gridwidth = mgridwidth;
        c.gridheight = mgridheight;
        c.weightx = mweightx;
        c.weighty = mweighty;
        if (button) {
            c.ipadx = 0;
            c.ipady = 10;
            c.insets = new Insets(10, 10, 10, 10);
        } else {
            c.ipadx = 0;
            c.ipady = 0;
            c.insets = new Insets(0, 0, 0, 0);
        }
    }
    /*
     * DONT call this: use it as a reference to make more protected JPanel
     * createRadioButtons(JRadioButton[] radioButtons, ButtonGroup radiogroup,
     * String a){ JPanel radioRow = new JPanel(); radioRow.setLayout(new
     * GridBagLayout());
     * 
     * radiogroup = new ButtonGroup();
     * 
     * for(int i = 0; i < radioButtons.length; i++){ radioButtons[i] = new
     * JRadioButton(""+(i+1)); radioButtons[i].setActionCommand(a+(i+1));
     * radioButtons[i].addActionListener(this); radiogroup.add(radioButtons[i]);
     * System.out.println(""+radiogroup.getButtonCount());
     * setConstraints(i,0,1,1,1.0f,1.0f,false); radioRow.add(radioButtons[i],
     * c); } if(radioButtons.length != 0)
     * radiogroup.setSelected(radioButtons[0].getModel(), true);
     * 
     * return radioRow; }
     */

}
